<form id="addIdentValueForm" lay-filter="addIdentValueForm" class="layui-form model-form">
    <input name="userId" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input name="name" placeholder="请输入名称" type="text" class="layui-input" maxlength="20"
                   lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">代码</label>
        <div class="layui-input-block">
            <input name="code" placeholder="请输入代码" type="text" class="layui-input" maxlength="20"
                   lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选择上级目录</label>
        <div class="layui-input-block">
            <input name="parname" placeholder="" type="text" class="layui-input" maxlength="20"
                   lay-verType="tips" lay-verify="required" disabled/>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
                        <textarea name="memo" placeholder="请输入描述信息" class="layui-textarea"
                                  lay-verType="tips" lay-verify="" ></textarea>
        </div>
    </div>
    <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closePageDialog">取消</button>
        <button class="layui-btn" lay-filter="addIdentValueSubmit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'form','admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;
        var Authorization;//请求接口用
        //获取权限方法
        var userInfo = getAuthority();
        if(userInfo){
            var access_token = localStorage.getExpire("access_token");
            var token_type = localStorage.getExpire("token_type");
            Authorization = token_type+" "+access_token;
        }

        var IdentValueSelected = window.IdentValueSelected;  // 列表页面传递的数据，也可以使用top.xxx
        var IdentGroupData = window.IdentGroupData ;

        // 回显数据
        var identValueSelectedNew = {
            parname:IdentValueSelected.name||'根目录'
        }
        form.val('addIdentValueForm', identValueSelectedNew);
        // 表单提交事件
        form.on('submit(addIdentValueSubmit)', function (data) {
            var formData = new FormData();
            formData.append('code ',data.field.code );
            formData.append('gid',IdentGroupData.gid);
            formData.append('memo',data.field.memo);
            formData.append('name ',data.field.name );
            formData.append('parcode ',IdentValueSelected.code||'root' );
            formData.append('sort',0);
            formData.append('vid',IdentGroupData.vid);
            axios({
                method: 'POST',
                url:microUrl.identValue.addEnum,
                data:formData,
                headers:{
                    'Authorization':Authorization
                }
            })
                .then(function (res) {
                    if (res.status == 200&&res.data.message=="success") {
                        window.addIdentValueFormIsOk = true;  // 设置操作成功的标识，也可以使用top.xxx                                               
                        layer.msg("新增成功", {icon: 1});
                        admin.closeDialog('#addIdentValueForm');  // 关闭页面层弹窗
                    } else {
                        layer.msg(res.data.message, {icon: 2});
                    }
                })
                .catch(function (error) {
                    console.log(error);
                    if(error.response.status === 401 || error.response.status === 403 || error.response.status === 406){
                        // 进行重新登陆
                        localStorage.clear();
                        top.location.href=loginPageUrl;
                    }
                })
            return false;
        });

    });
</script>